#include "Example_Bezier_Curve_Editor.h"
#include <sxOpenGL_DefaultCameraRenderer.h>
#include <sxOpenGL_DefaultPlotAxesRenderer.h>
#include <sxOpenGL_PickingController.h>
#include <sxOpenGL_Canvas.h>
#include <sxOpenGL_DefaultCuboidRenderer.h>
#include <sxOpenGL_DefaultBezierCurveRenderer.h>

/* SxLibrary Types. */
using Sx::QtInterface::QOpenGL_Viewport;
using Sx::Interface::BezierEditController;
using Sx::OpenGL::Graphics::Contexts::OpenGL_Context;
using Sx::OpenGL::Graphics::Objects::Rendering::OpenGL_DefaultCameraRenderer;
using Sx::OpenGL::Graphics::Picking::OpenGL_PickingController;
using Sx::OpenGL::Graphics::Objects::Rendering::OpenGL_DefaultPlotAxesRenderer;
using Sx::OpenGL::Graphics::Objects::Rendering::OpenGL_DefaultBezierCurveRenderer;
using Sx::OpenGL::Interface::OpenGL_Canvas;

Example_Bezier_Curve_Editor::Example_Bezier_Curve_Editor(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) {
	ui.setupUi(this);

	this->openglContext = std::make_shared<OpenGL_Context>();

	this->openglViewport = new QOpenGL_Viewport(this, this->openglContext, 120u);
	this->openglViewport->setRealtime(false);
	this->openglViewport->enableUserUpdates();

	this->bezierController = std::make_shared<BezierEditController>(
		this->openglViewport, 
		std::make_shared<OpenGL_Canvas>(this->openglContext), 
		std::make_shared<OpenGL_PickingController>(), 
		std::make_shared<OpenGL_DefaultCameraRenderer>(this->openglContext), 
		std::make_shared<OpenGL_DefaultPlotAxesRenderer>(this->openglContext), 
		std::make_shared<OpenGL_DefaultBezierCurveRenderer>(this->openglContext));

	this->bezierController->initialize();
	this->bezierController->setVariablePointCurve(true);

	this->openglViewport->setController(this->bezierController);
	this->openglViewport->setClearColor(0.2f, 0.2f, 0.2f);
}

Example_Bezier_Curve_Editor::~Example_Bezier_Curve_Editor() {}

void Example_Bezier_Curve_Editor::resizeEvent(QResizeEvent* e) {
	if ( this->openglViewport == nullptr ) return;
	this->openglViewport->resize(this->width(), this->height());
}
